home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CMouseControlsDirector.cp < prev    next >
Text File  |  1994-04-06  |  5KB  |  197 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| CMouseControlsDirector.cp
  3. //|
  4. //| This implements the controls dialog director
  5. //|_________________________________________________________
  6.  
  7. #include "CEditMouseControlsDirector.h"
  8. #include "CHyperCuberPrefs.h"
  9. #include "CMouseControlsArrayPane.h"
  10. #include "CMouseControlsDialog.h"
  11. #include "CMouseControlsDirector.h"
  12.  
  13. #include "HyperCuber Commands.h"
  14. #include "Mouse.h"
  15.  
  16. #include <CPopupMenu.h>
  17. #include <CStdPopupPane.h>
  18.  
  19. //============================ Globals ============================\\
  20.  
  21. extern CDesktop         *gDesktop;
  22. extern CHyperCuberPrefs *gPrefs;
  23.  
  24.  
  25.  
  26. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. // CMouseControlsDirector::IMouseControlsDirector
  28. //
  29. // Purpose: Initialize the controls dialog.
  30. //
  31. // Parameters: none
  32. //_________________________________________________________
  33.  
  34. void CMouseControlsDirector::IMouseControlsDirector (CDirectorOwner *aSupervisor)
  35. {
  36.  
  37. #define CONTROLS_DIALOG_ID    131
  38.  
  39.     CDialogDirector::IDialogDirector (aSupervisor);            //  Init superclass
  40.  
  41.     array = new(CArray);                                    //  Set up the array
  42.     array->IArray(sizeof(mouse_control_struct));
  43.  
  44.     array_pane = new (CMouseControlsArrayPane);                //  Create the array pane
  45.  
  46.     BuildArrayFromPrefs();                                    //  Build the array
  47.  
  48.     CMouseControlsDialog *dialog = new (CMouseControlsDialog);    //  Set up the mouse controls dialog
  49.     dialog->IMouseControlsDialog(CONTROLS_DIALOG_ID, gDesktop,
  50.                                     this, array, array_pane);
  51.     itsWindow = dialog;
  52.  
  53. }    //=== CMouseControlsDirector::IMouseControlsDirector() ===\\
  54.  
  55.  
  56.  
  57. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. //| CMouseControlsDirector::BuildArrayFromPrefs
  59. //|
  60. //| Purpose: These procedure builds the array from the preferences.
  61. //|
  62. //| Parameters: none
  63. //|______________________________________________________________________________
  64.  
  65. void    CMouseControlsDirector::BuildArrayFromPrefs(void)
  66. {
  67.  
  68.     while(array->GetNumItems())                                //  Clear array
  69.         array->DeleteItem(1);
  70.  
  71.     long i;
  72.     for (i = 0; i < gPrefs->prefs.num_mouse_controls; i++)
  73.         array->InsertAtIndex(
  74.                 &(gPrefs->prefs.mouse_controls[i]), 10000);    //  Add this mouse control to array
  75.  
  76. }    //==== CMouseControlsDirector::BuildArrayFromPrefs() ====\\
  77.  
  78.  
  79.  
  80. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. //| CMouseControlsDirector::DoCommand
  82. //|
  83. //| Purpose: Handle commands for the dialog.
  84. //|
  85. //| Parameters: none
  86. //|_________________________________________________________
  87.  
  88. void CMouseControlsDirector::DoCommand( long aCmd)
  89. {
  90.  
  91.     Cell                    cell;
  92.     mouse_control_struct    mouse_control;
  93.     Boolean                    selection;
  94.  
  95.     switch (aCmd)
  96.     {
  97.         
  98.         case cmdDefaults:
  99.         
  100.             PrefsStruct prefs = gPrefs->prefs;        //  Save the current prefs
  101.             gPrefs->SetDefaults();                    //  Set all preferences to default values
  102.  
  103.             BuildArrayFromPrefs();                    //  Rebuild the array with default values
  104.             
  105.             gPrefs->prefs = prefs;                    //  Restore the current prefs
  106.             break;
  107.     
  108.         case cmdEdit:
  109.         
  110.             cell.h = cell.v = 0;
  111.             selection = array_pane->GetSelect(TRUE, &cell);        //  Find highlighted cell, if any
  112.             if (!selection) break;                                //  Don't do anything if no selection
  113.             array->GetItem(&mouse_control, cell.v + 1);            //  Get the cell
  114.         
  115.             CEditMouseControlsDirector *ekcdialog_director = new (CEditMouseControlsDirector);
  116.             ekcdialog_director->IEditMouseControlsDirector(this, &mouse_control);
  117.             ekcdialog_director->TalkToUser();
  118.             ekcdialog_director->Dispose();
  119.  
  120.             array->SetItem(&mouse_control, cell.v + 1);            //  Change the cell
  121.             
  122.             break;
  123.         
  124.         case cmdAdd:
  125.  
  126.             cell.h = cell.v = 0;
  127.             selection = array_pane->GetSelect(TRUE, &cell);        //  Find highlighted cell, if any
  128.             
  129.             mouse_control.dimension = 3;                        //  Create a new mouse command
  130.             mouse_control.angle = 1;
  131.             mouse_control.horiz = TRUE;
  132.             mouse_control.multiplier = 1;
  133.             mouse_control.modifiers = 0;
  134.             
  135.             array->InsertAtIndex(&mouse_control, (selection) ?
  136.                             cell.v + 1 : 10000);                //  Insert a new cell before
  137.                                                                 //   selection or at end if none.
  138.             break;
  139.  
  140.         case cmdRemove:
  141.         
  142.             cell.h = cell.v = 0;
  143.             selection = array_pane->GetSelect(TRUE, &cell);        //  Find highlighted cell, if any
  144.             
  145.             if (selection)
  146.                 array->DeleteItem(cell.v + 1);                    //  Remove the cell
  147.  
  148.             break;
  149.         
  150.         
  151.         default:
  152.             inherited::DoCommand( aCmd);
  153.             break;
  154.     }
  155.     
  156. }    //=== CMouseControlsDirector::DoCommand ===\\
  157.  
  158.  
  159.  
  160. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161. // CMouseControlsDirector::TalkToUser
  162. //
  163. // Purpose: Handle commands for the dialog.
  164. //
  165. // Parameters: none
  166. //_________________________________________________________
  167.  
  168. void CMouseControlsDirector::TalkToUser(void)
  169. {
  170.  
  171.     long dismiss_command;
  172.     
  173.     BeginModalDialog();
  174.     long dismiss = DoModalDialog(cmdOK);
  175.     
  176.     if (dismiss == cmdOK)
  177.         {
  178.  
  179.         gPrefs->Lock(TRUE);
  180.         PrefsStruct *prefs = &(gPrefs->prefs);                    //  Get pointer to current prefs
  181.         prefs->num_mouse_controls = array->GetNumItems();
  182.  
  183.         long i;
  184.         for (i = 0; i < prefs->num_mouse_controls; i++)
  185.             {
  186.             mouse_control_struct mouse_control;
  187.         
  188.             array->GetItem(&mouse_control, i + 1);                //  Get the mouse control
  189.             prefs->mouse_controls[i] = mouse_control;            //  Move this mouse control to prefs
  190.             }
  191.  
  192.         gPrefs->Lock(FALSE);
  193.         
  194.         }
  195.     
  196. }    //=== CMouseControlsDirector::TalkToUser ===\\
  197.